package com.wang.web3.weight;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wang.web3.R;
import com.wang.web3.bean.GirlBean;

/**
 * Created by SAR on 2018/4/9.
 */

public class GirlRepoWindow extends DialogFragment implements View.OnClickListener{


    TextView tv_gril_info,tvPrice;
    ImageView mIvImg;
    Button mBtnRepo,mBtnCancel;
    GirlBean.DataBean dataBean;

    KittyWindowOnClick kitttyWindowOnClick;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.girl_repo_dialog, container, false);
        tv_gril_info = v.findViewById(R.id.tv_gril_info);
        tvPrice = v.findViewById(R.id.tvPrice);
        mIvImg = v.findViewById(R.id.mIvImg);
        v.findViewById(R.id.mBtnRepo).setOnClickListener(this);
        v.findViewById(R.id.mBtnCancel).setOnClickListener(this);
        Bundle bundle  = getArguments();
        dataBean = (GirlBean.DataBean) bundle.getSerializable("kittyInfo");
        Glide.with(getContext()).load(dataBean.getPicBody()).into(mIvImg);
        tv_gril_info.setText("少女" + dataBean.getId() + "---star :" + dataBean.getStar() + "---rare:"+dataBean.getRare() + "---race" + dataBean.getRace());

        return v;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onStart()
    {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm );
        getDialog().getWindow().setLayout( dm.widthPixels, getDialog().getWindow().getAttributes().height );
    }

    public void initOnClick(final KittyWindowOnClick kitttyWindowOnClick){
        this.kitttyWindowOnClick = kitttyWindowOnClick;
    }


    public static GirlRepoWindow showKitty(FragmentManager fragmentManager, GirlBean.DataBean kittyInfo) {
        GirlRepoWindow kittyWindow = new GirlRepoWindow();
        Bundle bundle = new Bundle();
        bundle.putSerializable("kittyInfo", kittyInfo);
        kittyWindow.setArguments(bundle);
        kittyWindow.show(fragmentManager, "kittyWindow");
        return  kittyWindow;
    }

    @Override
    public void onClick(View v) {
        kitttyWindowOnClick.onClick(v);
    }

    public interface KittyWindowOnClick{
        void onClick(View v);
    }
}
